package cn.test.learnkotlin.v1

class DLoopControl {

    private fun fooFor() {
        var array = arrayOf(1, 2, 3, 4, 5)
        for (i in array) {
            print(i)
        }
        for (i in array.indices) {
            print(array[i])
        }
        for (withIndex in array.withIndex()) {
            withIndex.index
            withIndex.value
        }
        for ((index, value) in array.withIndex()) {

        }
    }

    private fun fooWhile() {
        var x = 5
        while (x > 0) {
            print(x--)
        }
        print("\n")
        x = 5
        do {
            print(x--)
        } while (x > 0)
    }

    private fun fooBreakLoop() {
        for (i in 1..10) {
            if (i == 3) continue
            println(i)
            if (i > 5) break
        }
    }

    private fun fooLabel() {
        loop1@ for (i in 1..100) {
            loop2@ for (j in 1..100) {
                if (j == 10) break@loop2
                print(j)
                if (i == 2) break@loop1
            }
            print("\n")
        }
    }

    private fun fooReturn() {

    }

    fun main() {
        fooLabel()
    }
}

fun main() {
    DLoopControl().main()
}